home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18131 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: orchard.la.locus.com!news
  2. From: rhyde <rhyde@cs.ucr.edu>
  3. Newsgroups: comp.lang.c++,comp.programming
  4. Subject: Re: Young programmers read me.
  5. Date: 18 Apr 1996 21:13:08 GMT
  6. Organization: uc riverside
  7. Message-ID: <4l6b94$lr9@orchard.la.locus.com>
  8. References: <4icpp9$7hr@barad-dur.nas.com> <4keejc$lpi@tpd.dsccc.com> <Pine.OSF.3.91.960411093444.20958D-100000@bud.cc.swin.edu.au> <4kmfqn$e0f@airdmhor.gen.nz> <4kubt3$2jk@plains.nodak.edu> <4l0c8p$rvp@fountain.mindlink.net> <4l1dn6$j3@belle.bork.com>
  9. NNTP-Posting-Host: pcitest3.la.locus.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
  14.  
  15. scottr@belle.bork.com (Randy Scott) wrote:
  16. >Gene Wirchenko (genew@mindlink.bc.ca) wrote:
  17. >: >Try this:
  18. >: >       if(something_happened) do_something_else();
  19. >: 
  20. >:      Not as clear as it should be by my standards.  YMMV.
  21. >
  22. >NOT CLEAR?  Hello?  That piece of code is just about as clear as it
  23. >gets!
  24. >
  25. >: >or this:
  26. >: >       if(something_happened)
  27. >: >       {   do_something_else(); }
  28. >: 
  29. >:      Extraneous braces cause pause.
  30. >
  31. >I would have to agree, use braces only when absolutely necessary.
  32. >
  33. >
  34. >Randy Scott
  35.  
  36.  
  37. Although this is somewhat of a religious argument, we teach our students
  38. to always put in the braces even when there is only a single statement, .e.g,
  39.  
  40.     if (expression)
  41.     {
  42.           statement;
  43.     }
  44.  
  45.  
  46. This code is easier to maintain, always consistent, and (for most who've
  47. really studied the problem) easier to read.
  48.  
  49. Personally, I get rather upset when people "hide" braces at the end of
  50. other statements, e.g.,
  51.  
  52.     if (expression) {
  53.          statement;
  54.     }
  55.  
  56. or
  57.  
  58.     if (expression)
  59.     { statement; }
  60.  
  61. But that's my opinion.  I personally believe the first version above is better
  62. because it's easy to see where the block begins and ends, the statement to
  63. which it is attached, and the braces also add some needed whitespace to the
  64. program making it easier to read.  But once again, that's just my opinion,
  65. I'm not going to try to talk someone who has been doing some other way for
  66. 20 years out of their favorite indenting scheme.
  67.  
  68.  
  69.